<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>


<%
String userid=(String)session.getAttribute("userid");

%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title></title>
</head>
<title> 最近联系人</title>
<body >
<style>
*{margin:0 ;padding:0}
.lxr{
border:1px solid #f0f0f0; height:60px; width:100%
 
}
.right{
width:80%; float:left;  height:60px;
}
.lxrtx{
           width:20%; float:left;  height:60px;
		   position: relative;
}
 img {
        width: 50px;
        height: 50px;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -25px; /* 高度的一半 */
        margin-left: -25px; /* 宽度的一半 */
    }
.nickname{
    width:50%;  height:30px;    float:left; 
    position:relative; 
}
.time{
      width:50%;     height:30px; float:left ;  text-align:right   ;
      position:relative; 
	  	   
}
.mesage{
 width:80%;
 text-align:left;
overflow:hidden;
 text-overflow:ellipsis;  

}
.nickname p{
     position:absolute;
     bottom:0px;
     padding:0px;
     margin:0px;
	 color:#0080C0;
 }

 .time p{
      position:absolute;
      right:0;
      bottom:0;
	  color:#ABABAB;	    
 }
 
</style>
<div id="list">
 <%--  <div  id="lxr"  >
           <div id="lxrtx"  class="lxrtx" >  <img  src="image/doctor/1.jpg" /> </div>
		     <div   class="right">
		                <div  style="height:30px;">
			                         <div       class="nickname" ><p>{{todo.nickname}} </p></div>
				                     <div       class="time" ><p></p></div>
								  
			            </div>
		       <div class="message" >  <li>   <p        style=" color:#ABABAB">{{todo.msg[0][1]}}</p> </li></div>
		  </div>
     </div>
--%>

</div>

<script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script>

<!-- 强制使用移动端版本的kit -->
<script src="https://g.alicdn.com/aliww/h5.imsdk/2.1.5/scripts/yw/wsdk.js" charset="utf-8"></script>
<script src="js/jquery-1.4.2.min.js" language="JavaScript"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script>   
   var sdk = new WSDK();
function login(){
    sdk.Base.login({
        uid: '<%=userid%>',
        appkey:'24472009',
        credential: '123456',
        timeout: 6000,
        success: function(data){
              console.log('login success', data);
			
        },
        error: function(error){
           console.log('login fail', error);
        }
    });  
	}
	function  getRecentContact(){
	
	   sdk.Base.getRecentContact({
             count: 30, 
		     success: function(data){
             data = data.data;
             var list = data.cnts,
                type = '';
		         console.log('login success', data);
                 list.forEach(function(item){
					 console.log(item.msg)
              });	
          document.getElementById("list").innerHTML="";
             
           for(var i=0 ;i<list.length;i++) 
		    { 
			
                var  oDiv = document.createElement('div');
				     oDiv.id=list[i].uid.substr(8)
 		             document.getElementById("list").appendChild(oDiv);
					 oDiv.onclick=function(){
					 parent.location="mkits.jsp?doctor_logname="+this.id+""; 
	              };
				var  lxrtx=document.createElement('div');
				     lxrtx.className="lxrtx";
			    var  img=document.createElement('img');
				     img.src="image/doctor/1.jpg";
				     lxrtx.appendChild(img);
				     oDiv.appendChild(lxrtx);
			     var  right=document.createElement('div');
				      right.className="right";
                      oDiv.appendChild(right);
			     var  div =document.createElement('div');
				      div.style.height="30px";
			     var   nickname=document.createElement('div');
				      nickname.className="nickname";
				var   p=document.createElement('p');
			           nickname.appendChild(p);	 
					  p.innerHTML=list[i].nickname;
			     var   time=document.createElement('div');
				       time.className="time";
			      var   p1=document.createElement('p');
				       p1.innerHTML=getdate(list[i].time);
			          time.appendChild(p1);	
					  div.appendChild(nickname);	 
					  div.appendChild(time);	 
				 var    messge=document.createElement('div');
				        messge.className="mesage"
				  var   p3=document.createElement('nobr');
				        p3.style.color="#ABABAB";
				  var t=list[i].msg[0][1];
				   if(t.indexOf("mobileimweb/fileupload/downloadPriFile.do")>1){
			            t='[图片消息]';
			            }  
						
				        p3.innerHTML=t;	
						messge.appendChild(p3);	
				        right.appendChild(div);
					    right.appendChild(messge);
               }
		
		
        },
        error: function(error){
            console.log('获取最近联系人及最后一条消息内容失败' ,error);
        }
            });
	
	}
	window.onload=function(){ 
	login();
	getRecentContact();
	
	}
    window.setInterval(getRecentContact,1000);

    function  getdate(obj){
	 var data=new Date(parseInt(obj)*1000)
	 var datanian = data.getFullYear();
     var datayoue = data.getMonth() + 1;
     var dataday = data.getDate();
     var tody = new Date();
     var nian = tody.getFullYear();
     var youe = tody.getMonth() + 1;
     var day = tody.getDate();
	 var hour = data.getHours();
     var mins = data.getMinutes();
	 var  m=mins>10?mins:'0'+mins
	  var h=hour>10?hour:'0'+hour
	 if(datanian==nian&&datayoue==youe&&dataday==day)     
	            return  h+":"+m+"&nbsp;&nbsp;";
	 if(datanian==nian&&datayoue==youe)
	            return  datayoue+"月"+youe+"日"+"&nbsp;&nbsp;";
		 return datanian+"年"+ datayoue+"月"+youe+"日&nbsp;&nbsp;";

}
</script>
</body>
</html>